/**
 * 版权所有 (C), 2019-2019, XXX有限公司
 * 项目名：com.company.study.designpatterns.chain
 * 文件名: AbstractHandler
 * 日期: 2019/6/16 14:45
 * 说明:
 */
package com.company.study.designpatterns.chain;

/**
 * @author Anbang713
 * @create 2019/6/16
 */
public abstract class AbstractHandler implements Handler {
    /**
     * 下一个处理器
     */
    public Handler nextHandler;

    /**
     * 获取用户等级
     *
     * @return
     */
    protected abstract Integer getUserLevel();

    @Override
    public final String handleMessage(Integer level, String userName) {
        String result = "";
        if (this.getUserLevel().equals(level)) {
            result = this.operator(userName);
        } else {
            result = this.nextHandler.handleMessage(level, userName);
        }
        return result;
    }

    public Handler getNextHandler() {
        return nextHandler;
    }

    public void setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
    }
}